<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="/billing" prefix="b"%>
<%@page import="com.admin.service.ProvinceService"%>
<%
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1

//or response.setHeader("Cache-Control","no-store");//HTTP 1.1

response.setHeader("Pragma","no-cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计费后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/wbox.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/wbox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script type="text/javascript">
<!--
	$(function(){
		$(".list div").mousemove(function(){
			$(this).css("background","#E3EEFF");
		}).mouseout(function(){
			$(this).css("background","");
		});
		$("#isp").val('${user.isp}');
		$("#provinceId").val('${user.provinceId}');
		$("#sid").val('${user.sid}');
		$("#userType").val('${user.userType}');
		$("#telPhone").val('${user.telPhone}');
	});

	function view(userId){
		var wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:500,height:500},
			target:"<%=request.getContextPath() %>/admin/user/"+userId,
			title: "用户详细信息"
		});
		wBox.showBox();
	}

	function updateUserType(userId,userType){
		var htmlStr = "<form id=\"updateForm\" class=\"democss\"><table>";
		htmlStr +="<tr><th>用户类型：</th><td><select name=\"newUserType\" id=\"newUserType\" style=\"width:120px;\"/>";
		htmlStr +="<option value=0>白名单</option>";
		htmlStr +="<option value=1>灰名单</option>";
		htmlStr +="<option value=2>黑名单</option></td></tr>";
		htmlStr +="<tr><th>&nbsp;</th><td><input type=\"button\" value=\"修改\" class=\"submit\" onclick=\"update("+userId+");\"/></td></tr>";
		htmlStr +="</select>";
		
		htmlStr += "</table></form>";
		var wBox=$("#pop").wBox({
			title: "修改用户类型",
			html: htmlStr
		});
		wBox.showBox();
		$("#newUserType").val(userType);
	}

	function update(userId){
		$.ajax({
			url:"<%=request.getContextPath() %>/admin/user/update?userId="+userId+"&userType="+$('#newUserType').val(),
			type:"POST",
			success:function(flag){
				if(flag=='1'){
					alert("修改成功!");
					window.location.href="<%=request.getContextPath() %>/admin/user/";
				}else{
					alert("修改失败!");
				}
			}
		});
	}

	function delUser(userId){
		if(confirm("你确认删除该用户吗?")){
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/user/del/"+userId,
				type:"POST",
				success:function(flag){
					if(flag=='1'){
						alert("删除成功!");
						window.location.href="<%=request.getContextPath() %>/admin/user${pageBean.url }&currentPage=${pageBean.currentPage}";
					}else{
						alert("删除失败!");
					}
				}
			});
		}
	}
			
//-->
</script>
</head>
<body>
<div class="information">
	<div class="title">
		用户列表
	</div>
	<div class="search">
		<form action="<%=request.getContextPath() %>/admin/user" method="post">
		运营商：
		<select name="isp" id="isp" style="width:120px;">
			<option value="-1">-----请选择-----</option>
			<option value="0">移动</option>
			<option value="1">联通</option>
			<option value="2">电信</option>
		</select>
		<c:set value="<%=ProvinceService.getProvinceList() %>" var="provinceList"></c:set>
		省市：
		<select name="provinceId" id="provinceId" style="width: 120px;">
			<option value="">-----请选择-----</option>
			<c:forEach items="${provinceList}" var="p">
				<option value="${p.id }">${p.province }</option>
			</c:forEach>
		</select>
		厂商：
		<select name="sid" id="sid" style="width: 120px;">
			<option value="">-----请选择-----</option>
			<c:forEach items="${companyList}" var="p">
				<option value="${p.companyId }">${p.companyName }</option>
			</c:forEach>
		</select>
		用户类型：
		<select name="userType" id="userType" style="width:120px;">
			<option value="">-----请选择-----</option>
			<option value="0">白名单</option>
			<option value="1">灰名单</option>
			<option value="2">黑名单</option>
		</select>
		手机号码:<input type="text" name="telPhone" id="telPhone" size="20">
		<input type="submit" value="查询">
		</form>
	</div>
	<div class="listTitle">
		<ul>
			<li style="width:40px;">编号</li>
			<li style="width:100px;">手机号</li>		
			<li style="width:80px;">厂商</li>		
			<li style="width:80px;">机型</li>
			<li style="width:60px;">省份</li>
			<li style="width:100px;">版本</li>
			<li style="width:60px;">移动商</li>
			<li style="width:80px;">用户类型</li>
			<li style="width:150px;">注册时间</li>
			<li style="width:120px;">操作</li>
			<li style="width:60px;">删除</li>
		</ul>
		<div class="clear"></div>
	</div>
	<div class="list">
		<c:forEach items="${pageBean.result}" var="user" varStatus="status">
			<div class="${status.index%2==0?'noselect':'select' }">
				<ul>
					<li style="width:40px;">${user.userId}</li>
					<li style="width:100px;">${user.telPhone }&nbsp;</li>	
					<li style="width:80px;">${user.companyName }</li>		
					<li style="width:80px;">${user.mobileTypeName }</li>
					<li style="width:60px;"><b:province provinceId="${user.provinceId }"/>&nbsp;</li>
					<li style="width:100px;">${user.softwareVersion }&nbsp;</li>
					<li style="width:60px;">
						<c:choose>
							<c:when test="${user.isp==0 }">移动</c:when>
							<c:when test="${user.isp==1 }">联通</c:when>
							<c:when test="${user.isp==2 }">电信</c:when>
						</c:choose>
					</li>
					<li style="width:80px;">
						<c:choose>
							<c:when test="${user.userType==0 }">白名单</c:when>
							<c:when test="${user.userType==1 }">灰名单</c:when>
							<c:when test="${user.userType==2 }">黑名单</c:when>
						</c:choose>
					</li>
					<li style="width:150px;">${user.createTime }</li>
					<li style="width:120px;">
						<a href="#" onclick="view('${user.userId}')">查看</a>
						<a href="#" onclick="updateUserType('${user.userId}','${user.userType}')">修改用户类型</a>
					</li>
					<li style="width: 60px;">
						<a href="#" onclick="delUser('${user.userId}')">删除</a>
						<!--<c:choose>
							<c:when test="${user.sid=='19'}"></c:when>
							<c:otherwise>非测试用户</c:otherwise>
						</c:choose>-->
					</li>
				</ul>
				<div class="clear"></div>
			</div>
		</c:forEach>
	</div>
	<jsp:include page="../page.jsp" flush="true"></jsp:include>
</div>
</body>
</html>